class Solution {
public:
    int numberOfWeakCharacters(vector<vector<int>>& properties) {
        sort(properties.begin(), properties.end(), [](const vector<int>& a, const vector<int>& b) {
            return a[0] == b[0] ? (a[1] < b[1]) : (a[0] > b[0]);
            });
        int def = 0;
        int ans = 0;
        for (auto& k : properties)
        {
            if (k[1] < def)
            {
                ans++;
            }
            else
            {
                def = k[1];
            }
        }
        return ans;
    }
};